<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->model("model_user");
	}
	function index(){
		echo "user controller";
	}
	function register(){
		$uname = $_POST["uname"];
		$password = $_POST("password");
		$arr = array("uname"=>$uname,"password"=>$password);
		$this->model_user->insert($arr);
	}
	function update(){
		$arr = array("uid"=>6,"uname"=>"fjf","password"=>"xiu");
		echo $this->model_user->update($arr);
	}
	function login(){
		$uname = $_POST["uname"];
		$password = $_POST["password"];
		$result = $this->model_user->check($uname,$password);
		echo json_encode($result[0]);
	}
	function exist($uname){
		$result = $this->model_user->find_name($uname);
		echo empty($result)?"false":"true";
	}
	function upload_head(){
		$type = explode("/",$_FILES["header"]["type"]);
		$config["upload_path"]="./web/img/header/";
		$config["allowed_types"]="gif|jpg|jpeg|png";
		$config["max_size"]="20000";
		$config["file_name"]=date("YmdHis").".".$type[1];
		$this->load->library("upload",$config);
		if(!$this->upload->do_upload("header")){
			$error = $this->upload->display_errors();
			$this->model_user->set_header();
			print_r($error);
		}
		else{
			$data = $this->upload->data();
			print_r($data);
		}
	}
}